package com.charles.springcloud.controller;

import com.charles.springcloud.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 风中灵劲草
 * @Date: 2021/08/07/18:33
 * @Description:
 */
@RestController
@Slf4j
@RequestMapping("/consumer")
//@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod" , commandProperties = {
//        @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds" , value = "3000")})
public class OrderHystrixController {

    @Autowired
    private PaymentHystrixService paymentHystrixService;

    @GetMapping("/payment/hystrix/ok/{id}")
    public String paymentInfo_Ok(@PathVariable("id") Integer id){
        String result = paymentHystrixService.paymentInfo_Ok(id);
        return result;
    }

    @GetMapping("/payment/hystrix/timeOut/{id}")
//    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOut_FallbackMethod" , commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds" , value = "1500")
//    })
//    @HystrixCommand(commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds" , value = "2000")
//    })
//    @HystrixCommand
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
        String result = paymentHystrixService.paymentInfo_TimeOut(id);
        return result;
    }

    public String paymentInfo_TimeOut_FallbackMethod(@PathVariable("id") Integer id){
        return "我是消费者80,对方支付系统繁忙请10s后再试或者请检查自己程序是否出错";
    }

    public String payment_Global_FallbackMethod(){
        return "Global异常处理,对方系统繁忙请稍后再试！";
    }


}
